OpenBuildings GenerativeComponents Help

Script Console Examples

The following examples provide a very brief overview of the kinds of things you can do in GCScript. Please type each of these expressions or statements into the entry field and press Enter after each one.

Text to Enter Remarks

2+3

2 + 3

Generally, spacing doesn’t matter. It’s a matter of personal preference.

2 + 3 * 4

(2 + 3) * 4

You can use parentheses to force a particular sequence of calculation.

Sqrt (25)

Series (0, 20, 2)

Round (34, 67)

Print('The value of pi is roughly', PI)

GCScript includes many built-in functions.

int total = 5 + 9

total

total / 10

You can define your own variables, which let you record intermediate results.

The first time, and only the first time, that you use a variable, you must specify its value type; in this case, int.

(The first statement does not produce a result because, in that case, there is no result.)

int total = 3 * 4

total = 3 * 4

This entry won’t work! GenerativeComponent will complain that the variable total has already been defined (from the previous example).

To assign a new value to a preexistent variable, simply use the variable’s name, without a data type specifier.

(Note that you can never change the data type of a preexistent variable.)

double radius = 4.5

radius * 2 * PI

string greeting = 'Hello'

greeting + ' everyone'

GCScript supports several types of data.

int n = 11

n * 4

n = {11, 100, -2}

n * 4

GCScript works with lists of values as easily as single values. This is called automatic replication.

You use curly braces to enter a list of specific values, as shown.

string text = 'GC is cool'

text.Type

text.Substring (3, 6)

Values have properties and methods that we can use.

int sum = 9 + 5

sum > 10

sum == 14

sum.IsList

You can make comparisons and other kinds of tests.

if (sum > 10) sum = 10

sum.IsList ? 'replicated' : 'single'

You can perform different actions based on the results of tests.

for (int i = 0; i < 10; ++i) Print(i)

You can perform repetitious operations with looping statements.

double f (double r) { return r * 2 * PI; }

f (3.5)

f (1000)

You can define your own functions.

The body of the function (which in this example comprises the single 'return' statement) is enclosed in curly braces.